﻿#include "save_file.h"

save_file::save_file(QObject *parent) : QObject(parent)
{
}

int save_file::openfile(QString file_name)
{
    int rc = 0;
    fd.setFileName(file_name);
    if (!fd.open(QIODevice::Truncate | QIODevice::WriteOnly))
    {
        rc = -1;
        qDebug() << "open error";
        return rc;
    }
    return rc;
}

void save_file::writefile(char *res_buf, qint64 res_buf_size)
{
    qint64 rc = 0;
    rc = fd.write(res_buf, res_buf_size);
    if ((rc > 0) && (rc < res_buf_size))
    {
        qDebug() << "write buf:" << rc << "!=" << res_buf_size;
    }
    if (!fd.flush())
    {
        qDebug() << "Error flushing file:" << fd.errorString();
    }
}

void save_file::writefile(const QByteArray *data)
{
    qint64 rc = 0;
    rc = fd.write(*data);
}
void save_file::closefile()
{
    fd.close();
}
